﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Base.Utils;
using Chinook.Core;
using Chinook.Core.DomainModel;
using Chinook.Core.DaoInterface;
using Base.Utils.Logging;
using Chinook.Facade;
using Chinook.Facade.Factory;
using Chinook.Facade.ViewModel;
using Chinook.Facade.Messaging;
using Chinook.Web;
using System.Xml;
using System.Xml.Linq;
using System.Text.RegularExpressions;
using System.IO;
namespace Chinook.Web
{
    public partial class _Default : BasePage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            //IEmployeeDao employeeDao = new EmployeeDao("");
            //List<Employee> employees  = employeeDao.GetAll();
            //int _i=0;
            //for(_i=0;_i<employees.Count;_i++)
            //{
            //    Logger.Log(employees[_i].ToString(), LogType.Debug);
            //}


            IProfilerService profilerService = ChinookWebFactory.ProfilerService;
            var classes = profilerService.DistinctClasses();
            var methods = profilerService.DistinctMethods("Dole.EPM.Facade.DoleEpmAppService");
            var logs1 = profilerService.GetAll("Dole.EPM.Facade.DoleEpmAppService", "GetWorkOrderSearch");
            var logs2 = profilerService.GetAllByTimeRange(DateTime.Now.AddDays(-1),DateTime.Now, "Dole.EPM.Facade.DoleEpmAppService", "GetWorkOrderSearch");
            
            
            
            
            //IEmployeeAppService empAppSer = ChinookWebFactory.EmployeeAppService;
            //LookUpEmployeeRequest request = new LookUpEmployeeRequest();
            //LookUpEmployeeResponse response = empAppSer.LookupEmployee(request);
          
            //IProfilerService ps = new ProfilerService(AbsoluteWebRoot + "logs/epm.log.xml");
            //List<LogData> logs = ps.GetAll();
            //var result4 = logs.FindAll(log => log.ExecutionDateAndTime >= DateTime.Now.AddDays(-1) && log.ExecutionDateAndTime <= DateTime.Now);
            //var result = logs.FindAll(log => log.MethodName == "GetWorkOrderSearch");
            //var result2 = logs.GroupBy(log => log.MethodName).Select(grp => grp.First());
            //var result3 = logs.GroupBy(log => log.MethodName).Select(grp => grp.First()).Select(mn =>mn.MethodName); 
            //var distinctValues = 
            //    from mtd in logs 
            //    group mtd by mtd.MethodName        into gmtd
            //    select gmtd.First();

            // var log = ps.GetLogAsXmlReader(AbsoluteWebRoot + "logs/epm.log.xml");
            

            //XNamespace log4j = "http://www.w3.org/TR/html4/";
            //XElement main = XElement.Load(log);
            //List<LogData> lstLogs = new List<LogData>();
            //var query = from w in main.Descendants(log4j + "event")
            //            select w;
            //foreach (var record in query)
            //{

            //    LogData logData = new LogData();
            //    logData.Message = (string)record;
            //    logData.TimeStamp = Base.Utils.CommonUtils.StrToLong(((string)record.Attribute("timestamp")).Substring(0, 10));
            //    logData.ClassName = Regex.Split(logData.Message, "] ")[0].Replace("[", "");
            //    logData.MethodName = logData.ClassName.Split('.')[logData.ClassName.Split('.').Length - 1];
            //    logData.ClassName = logData.ClassName.Replace("." + logData.MethodName, "");
            //    logData.ExecutionTime = Base.Utils.CommonUtils.StrToDouble(Regex.Split(logData.Message, "=")[1]);
            //    lstLogs.Add(logData);
            //}

            }
        }
}
